package com.uenpay.im.ui.old.activity.personal;

import com.qiyunxin.android.http.listener.OnHttpRequestTextListener;
import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.net.HttpRequestAsyncTaskQueue;
import com.qiyunxin.android.http.net.HttpRequestType;
import com.qiyunxin.android.http.net.HttpTextAsyncTask;
import com.uenpay.im.ui.old.activity.pwd.ResetPayPwdInvokItem;
import com.uenpay.im.callback.OnCommonCallBack;
import com.uenpay.im.invokeitems.person.UpdateInfoInvokItem;

/**
 * 修改个人信息
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * 
 */
public class UpdatePersonInfoCommonHandle {

	public static void udpatePersonInfo(String field, String value,
			final OnCommonCallBack mBack) {
		UpdateInfoInvokItem item = new UpdateInfoInvokItem(field, value);
		HttpRequestAsyncTaskQueue
				.getInstance()
				.AddTask(
						new HttpTextAsyncTask(item)
								.SetRequestType(HttpRequestType.SERVER_ONLY),
						new OnHttpRequestTextListener() {

							@Override
							public void OnFail(boolean isCache, String reason) {
								mBack.onFailed(reason);
							}

							@Override
							public void OnProgress(long total_bytes,
									long downloaded_bytes) {
							}

							@Override
							public void OnSuccess(HttpInvokeItem item,
									boolean isCache, String cacheFilePath) {
								UpdateInfoInvokItem.UpdateInfoInvokItemResult result = ((UpdateInfoInvokItem) item)
										.getOutput();
								mBack.onSuccess(result);
							}
						});
	}
	
	public static interface ISetPayPwdResultListener {
		public abstract void onPayPwdResult(int status, String msg);
	}

 
	/**
	 * 重置支付密码
	 * 
	 * @param payPwd
	 * @param verCode
	 * @param mISetPayPwdResultListener
	 */
	public static void resetPayPwd(String payPwd, String verCode,
			final ISetPayPwdResultListener mISetPayPwdResultListener) {
		ResetPayPwdInvokItem item = new ResetPayPwdInvokItem(payPwd, verCode);
		HttpRequestAsyncTaskQueue
				.getInstance()
				.AddTask(
						new HttpTextAsyncTask(item)
								.SetRequestType(HttpRequestType.SERVER_ONLY),
						new OnHttpRequestTextListener() {

							@Override
							public void OnFail(boolean isCache, String reason) {
								mISetPayPwdResultListener.onPayPwdResult(-1,
										reason);
							}

							@Override
							public void OnProgress(long total_bytes,
									long downloaded_bytes) {
							}

							@Override
							public void OnSuccess(HttpInvokeItem item,
									boolean isCache, String cacheFilePath) {
								ResetPayPwdInvokItem.ResetPayPwdInvokItemResult result = ((ResetPayPwdInvokItem) item)
										.getOutput();
								if (result != null) {
									mISetPayPwdResultListener.onPayPwdResult(
											result.status, result.msg);
								} else {
									mISetPayPwdResultListener.onPayPwdResult(
											-1, "");
								}
							}
						});
	}


}
